var decorate = new Vue({
    el: '#app',
    data: {
        num: 0,
        serial: 1,
        data: [],
        title: null,
        A: null,
        B: null,
        C: null,
        D: null,
        right: [],
        main_title: "请输入标题",
        title_data:{0:"暂时没有作业"},
    },
    methods: {
        clear: function () {
            this.title = null;
            this.A = null;
            this.B = null;
            this.C = null;
            this.D = null;
            this.right = []
        },
        add_questions: function () {
            this.main_title = this.main_title;
            this.data.push({
                title: this.title,
                right: this.right,
                A: this.A,
                B: this.B,
                C: this.C,
                D: this.D
            })
            console.log(this.data);
            this.clear()

            // 因为数据push后，视图更新不是同步的，需要等到页面更新后才能获取到最新的高度
            this.$nextTick(() => {
                console.log(window.parent.document.getElementById('iframeBox'), 'asdfasdf',  window.document.documentElement.offsetHeight)
                window.parent.document.getElementById('iframeBox').style.height = window.document.documentElement.offsetHeight + 5 + 'px'
            })
        },
        del_questions: function (id) {
            this.data.splice(id,1)
        },
        add_homework: function () {
            console.log(this.data);
            const data = JSON.stringify({ data: this.data ,main_title:this.main_title})
            console.log(data);
            axios.post('http://127.0.0.1:8000/api/add_homework_teacher', `${data}`).then(function (res) {
                    // console.log(res);
    
                    if (res.data.status !== 0) {
                        return alert(res.data.message)
                    }
                    // localStorage.setItem('token', res.token)
                    // // 跳转到后台主页
                    // location.href = './student/student_index.html'
                this.main_title = "";
                this.data={}
                alert(res.data.message);
            })
            // this.clear()
        },

    },


})